<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChTalkKeywordCate;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;
use function Hyperf\Collection\data_get;

class ChTalkKeywordCateMapper extends AbstractMapper
{
    public function assignModel()
    {
        $this->model = ChTalkKeywordCate::class;
    }

    public function handleSearch(Builder $query, array $params): Builder
    {
        $type = data_get($params, 'type', 0);

        $query->where('main_uid',$params['main_uid']);

        if($type != 1){
            $query->where('uid',$params['uid']);
        }

        $query->where('type',$type);

        if(isset($params['parent_id']) && filled($params['parent_id'])){
            $query->where('parent_id',$params['parent_id']);
        }


        return $query;
    }
}